<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="租户名称" prop="userName">
        <el-input
          v-model="queryParams.name"
          placeholder="租户名称"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租户信用代码" prop="email" label-width="130px">
        <el-input
          v-model="queryParams.creditCode"
          placeholder="租户信用代码"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批状态" prop="auditStatus" label-width="100px">
        <el-select
          v-model="queryParams.auditStatus"
          size="small"
          placeholder="请选择"
          style="width:150px"
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in dict.type.audit_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleEmpty"
          v-hasPermi="['tenant:audit:empty']"
        >清空</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="auditRecordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="操作类型" align="center" prop="auditType" :formatter="auditTypeFormat"/>
      <el-table-column label="审批人" align="center" prop="auditUserName" />
      <el-table-column label="审批资源类型" align="center" prop="resourceType" :formatter="resourceTypeFormat" />
      <el-table-column label="审批拒绝理由" align="center" prop="rejectReason" />
      <el-table-column label="审批状态" align="center" prop="auditStatus" :formatter="enterFormat" />
      <el-table-column label="审批时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAuditRecords} from "@/api/tenant/approve/approve";

export default {
  name: "Approve",
  dicts: ['sys_user_sex', 'audit_status'],
  data() {
    return {
      operationType: true,
      // 遮罩层
      loading: true,
      // 选中数组
      uids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //获取的目录列表
      auditRecordsList:[],
      // 查询参数
      queryParams: {
        resourceType: 3,
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模板列表 */
    getList() {
      this.loading = true;
      this.queryParams.resourceType = 3;
      listAuditRecords(this.queryParams).then(response => {
        this.auditRecordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //table表格格式化
    enterFormat(row, index){
      if (row.auditStatus === 0) {
        return "待审批";
      } else if(row.auditStatus === 1){
        return "审核未通过";
      }else{
        return "审核通过"
      }
    },
    resourceTypeFormat(row, index){
      if (row.resourceType === 1) {
        return "芯片审批";
      } else if(row.resourceType === 2){
        return "资讯审批";
      }else{
        return "入驻审批"
      }
    },
    auditTypeFormat(row, index){
      if (row.auditType === 1) {
        return "自动审批";
      } else if(row.auditType === 2){
        return "手动审批";
      }
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.uids = selection.map(item => item.uid)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleEmpty(row) {
    },
  }
};
</script>
